
function powLow(a, b) {
    let ans = 1, base = a;
    while (b > 0) {
        ans *= base;
        b--;
    }
    return ans;
}

function poww(a, b) {
    let ans = 1, base = a;
    while (b != 0) {
        if (b & 1 != 0) {
            ans *= base;
        }
        base *= base;
        b >>= 1;
    }
    return ans;
}

function poww2(a, b) {
    let ans = 1, base = a;
    while (b != 0) {
        if (b % 2) {
            ans *= base;
        }
        base *= base;
        b = Math.floor(b / 2);
    }
    return ans;
}

console.log("3^0:", Math.pow(3, 0), powLow(3, 0), poww(3, 0), poww2(3, 0));
console.log("3^3:", Math.pow(3, 3), powLow(3, 3), poww(3, 3), poww2(3, 3));
console.log("3^4:", Math.pow(3, 4), powLow(3, 4), poww(3, 4), poww2(3, 4));